package com.cgbl.service.vm

import android.app.Application
import android.os.Bundle
import api.WorkServiceFactory
import com.blankj.utilcode.util.TimeUtils
import com.cgbl.service.assist.ProjectAssist
import com.cgbl.service.assist.TransferAssist
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.common.api.AbstractViewModelSubscriber
import com.robot.base.configs.AppConstants
import com.robot.base.model.BaseResponse
import com.robot.base.model.MemberAdapterBean
import com.robot.base.model.ProjectBean
import com.robot.base.util.arouter.ARouterUtil
import me.goldze.mvvmhabit.binding.command.BindingAction
import me.goldze.mvvmhabit.binding.command.BindingCommand
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent

class MemberFrameViewModel(application: Application) : GLBaseViewModel(application) {


    val uc = UIChangeEvent()

    class UIChangeEvent {

        val getMemberEvent = SingleLiveEvent<List<MemberAdapterBean>>()
    }

    val clickAddMemberCommand = BindingCommand<Any>(BindingAction {
        ARouterUtil.goToActivityWithBundle(
            AppConstants.Router.Project.A_ADD_MEMBER,
            Bundle().apply {
                putInt(
                    AppConstants.BundleKey.SELECT_MEMBER_TYPE,
                    AppConstants.BundleValue.SELECT_MEMBER_TYPE_FRAME
                )
            })
    })

    fun refreshProjectProfile(id: String) {
        WorkServiceFactory.get(id)
            .subscribe(object : AbstractViewModelSubscriber<BaseResponse<ProjectBean>>(this) {
                override fun onNext(t: BaseResponse<ProjectBean>) {
                    uc.getMemberEvent.postValue(t.data.accountDOS)
                }
            })
    }

}